import Vue from 'vue';
import routes from './routes';  
import './public/css/public.scss';

window.app = new Vue({
  el: '#app', 
  data: {
    currentRoute: ''
  },
  computed: {
    ViewComponent () { 
 
      const matchingView = routes[this.currentRoute.split("?")[0]]  
      return matchingView
        ? require('./pages/' + matchingView + '.vue')
        : require('./pages/404.vue');
    }
  },
  render (h) { 
    return h(this.ViewComponent);
  }
});

window.app.__proto__.go = function(strHash) {
   window.location.href = "#" + strHash;
}

window.app.__proto__.globalGo = function(url) {
   window.location.href = url;
}

window.addEventListener('popstate', function (event) { 
  console.log(window.location.pathname); 
})

window.addEventListener("DOMContentLoaded", function () { 
  console.log(window.location.pathname);
  app.currentRoute = window.location.pathname;
}, false);